﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://shiro.apache.org/tags" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/WEB-INF/view/include/jQgrid.jsp"%>

<link type="text/css" rel="stylesheet" href="<%=contextPath %>/plugins/zTree/2.6/zTreeStyle.css"/>
<script type="text/javascript" src="<%=contextPath %>/plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
</head>
<body>
	<div class="container-fluid" id="main-container">
		<div id="page-content" class="clearfix">
			<div class="row-fluid">
					<div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;"   id="table1">
						<div style="width: 20%; float: left; padding-right: 15px; ">
								<div id="zhongxin" style=" height: 600px;  background-color: #F5F5F5;overflow: hidden;">
										<ul id="tree" class="tree"></ul>
								</div>
						</div>
						<div class="jqGrid_wrapper" style="float: left; width: 80%;">
							<table id="table_list"></table>
							<div id="pager_list"></div>
						</div>
					</div>
					<!-- tableover -->
				</div>
				<!-- PAGE CONTENT ENDS HERE -->
			<!--/row-->
		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->
	<script>
	var zTree;
	var treeNodes;
	$(document).ready(function(){
			var setting = {
				isSimpleData : true,              //数据是否采用简单 Array 格式，默认false  
				treeNodeKey : "depId",               //在isSimpleData格式下，当前节点id属性  
				treeNodeParentKey : "pid",        //在isSimpleData格式下，当前节点的父节点id属性  
				showLine: true,
				callback: {
					beforeClick: function(treeId, treeNode) {
						if (treeNode.isParent) {
							/* zTree.expandNode(treeNode); *///点击展开关闭
							ss(treeNode.depId,true);
						} else {
							ss(treeNode.depId,false);
						}
					}
				},
			};
			  $.ajax({  
			        async : false,  
			        cache:false, 
			        type: 'POST',  
			        dataType : "json",  
			        url:"<%=contextPath %>/dep/getAll", 
			        success:function(data){ //请求成功后处理函数。    
			            treeNodes = data;   //把后台封装好的简单Json格式赋给treeNodes  
			        },error: function () {//请求失败处理函数  
			            alert('请求失败');  
			        } 
			    });  
			  
		/* 	var zn = '${zTreeNodes}';
			var zTreeNodes = eval(zn); */
			zTree = $("#tree").zTree(setting, treeNodes);
			var zTreeObj = zTree;
			var depid = ${dep_in_session.depId};
			var node = zTreeObj.getNodeByParam("depId", depid);
			zTreeObj.selectNode(node);
		});
	</script>

	<script type="text/javascript">
		$(top.hangge());
		$(function(){
			var flog = ${depflog_in_session};
			var logdepid = ${dep_in_session.depId};
			var userid = ${user_in_session.id};
			$("#table2").hide();
			$.jgrid.defaults.styleUI = "Bootstrap";
			$("#table_list").jqGrid({
				url: '<%=contextPath %>/user/getAll',
				postData:{'depid':logdepid,"flag":flog},
				datatype : "json",
				autowidth : true,
				shrinkToFit : true,
				mtype : "post",
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				colNames : ["id", "用户名", "姓名", "电话", "邮箱", "上次登录时间", "上次登录IP","状态","操作"],
				colModel : [{
					name : "id",
					index : "id",
					hidden:true
				}, {
					name : "username",
					index : "username",
					width : 90
				}, {
					name : "truename",
					index : "truename",
					width : 50
				}, {
					name : "mobile",
					index : "mobile",
					width : 80
				}, {
					name : "email",
					index : "email",
					width : 80
				}, {
					name : "lastLoginTime",
					index : "lastLoginTime",
					width : 80,
					sorttype:"date",
					formatter:"date",
					formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}
				}, {
					name : "lastLoginIp",
					index : "lastLoginIp",
					width : 100
				},{
					name : "state",
					index : "state",
					width : 80,
					formatter:function(cellvalue, options, row){
						if(cellvalue==1){
					         return "<a class='btn btn-sm btn-success'>正常</a>";
					    }
						if(cellvalue==2){
					         return "<a class='btn btn-sm btn-default'>删除</a>";
					    }
						if(cellvalue==3){
					         return "<a class='btn btn-sm btn-primary'>停用</a>";
					    }
					}
				},{
					formatter:function(cellvalue, options, row){
						if(userid==row.id){
							return " <a class='btn btn-mini btn-warning' title='修改密码' onclick='showeditpwd("+row.id+")'><i class='icon-pencil'></i></a> "
					     	   +" <a class='btn btn-mini btn-info' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a>";
						}else{
							return " <s:hasPermission name="dep:admin"><a class='btn btn-mini btn-warning' title='修改密码' onclick='showeditpwd("+row.id+")'><i class='icon-pencil'></i></a></s:hasPermission> "
					     	   +" <s:hasPermission name="dep:admin"><a class='btn btn-mini btn-info' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a></s:hasPermission> "
							   +" <s:hasPermission name="dep:admin"><a class='btn btn-mini btn-danger' title='删除' onclick='del("+row.id+")'><i class='icon-trash'></i></a></s:hasPermission> ";
						}
					},
					width : 100
				} ],
				height : $(window).height() - 170,
				pager : "#pager_list",
				//multiselect: true,//多选按钮
				//multiboxonly: true,
				viewrecords : true,
				hidegrid : false  
				/*   loadComplete: function(){
					  alert("sss");
					  ss(4,false);
				  } */  //加载完成触发事件
			});
			//表格自适应高宽
			$(window).bind("resize", function() {
				var b = $(".jqGrid_wrapper").width();
				$("#table_list").setGridWidth(b);
				$("#table_list").setGridHeight($(window).height() - 170);
			})
			$("#table_list").navGrid('#pager_list',{edit:false,add:false,del:false,search:false}).navButtonAdd('#pager_list',{   
				   caption:"",    
				   buttonicon:"glyphicon glyphicon-plus", 
				   onClickButton: function(){ 
					   var zTreeObj  =zTree;
					   var selectedNode = zTreeObj.getSelectedNode();
					  if(selectedNode.companyId==null){
						  toastr.options = {
									"closeButton": false, //是否显示关闭按钮
									"debug": false, //是否使用debug模式
									"positionClass": "toast-top-full-width",//弹出窗的位置
									"showDuration": "300",//显示的动画时间
									"hideDuration": "1000",//消失的动画时间
									"timeOut": "5000", //展现时间
									"extendedTimeOut": "1000",//加长展示时间
									"showEasing": "swing",//显示时的动画缓冲方式
									"hideEasing": "linear",//消失时的动画缓冲方式
									"showMethod": "fadeIn",//显示时的动画方式
									"hideMethod": "fadeOut" //消失时的动画方式
									};
						  toastr.warning("请先选中部门");
					  }else{
						  openyem("添加用户","<%=contextPath %>/user/addView?depid="+selectedNode.depId,400,750);
					  }
					   
				   }, 
				   position:"first"  
				});
			//检索
			$("#find_btn").click(function(){ 
		        var userName = $("#userName").val(); 
		        $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'userName':userName}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		    });  
		});
	      
		function ss(depId,bool){
			  $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'depid':depId,"flag":bool}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		}
		
		
		//删除
		function del(id){
			swalopen(id,"<%=contextPath %>/user/delete");
		};
		
		//修改
		function showedit(id){
			openyem("修改用户","<%=contextPath %>/user/editView?id="+id,300,550);
		}
		
		//修改密码
		function showeditpwd(id){
			openyem("修改密码","<%=contextPath %>/user/editpwdView?id="+id,300,340);
		}
  </script>
</body>
</html>

